#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#define int long long
#define x first
#define y second

using namespace std;

class Solution {
public:
    int diagonalPrime(vector<vector<int>>& nums) {
        if (nums.empty() || nums[0].empty()) {
            return 0;
        }

        int maxPrime = 0;
        auto N = nums.size();
        for (int i = 0; i < N; i++) {
            if (isPrime(nums[i][i])) {
                maxPrime = max(maxPrime, nums[i][i]);
            }

            if (isPrime(nums[N - 1 - i][i])) {
                maxPrime = max(maxPrime, nums[N - 1 - i][i]);
            }
        }

        return maxPrime;
    }

private:
    bool isPrime(int n) {

        if (n == 1) {
            return false;
        }
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                return false;
            }
        }

        return true;
    }
};

void solve()
{
    int len;
    cin >> len;
    vector<vector<int>> ret(len);
    for (int i = 0; i < len; i++)
    {
        ret[i] = vector<int>(len);
        for (int j = 0; j < len; j++)
        {
             cin >> ret[i][j];
        }
    }
    Solution s;
    cout << s.diagonalPrime(ret) << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int t = 1;
    while(t -- )  solve();
    return 0;
}